package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.MerinfoStatus;
import com.roc.util.constant.Role;

public class MerinfoAlloatSearchCondtion extends BaseSearchCondition{

	
	private String orgCode;//机构号
	private String roleId; //角色 
	private long agentId;//所属代理商
	private String merchantNo;//商户号
	private String merchantName;//商户简称
	private String  merBrName; //注册名称
	//private String status;//状态
	private int  merinfoFlag;//商户状态
	private  String  opId;//操作员id
	private String  minDate;//入网时间
	private String  maxDate;//入网时间
	private String  certifName;//法人
	private String  cardNo; //法人身份证
	private String  contactName;//业务联系人
	private String  phone;//联系电话
	private String  accountNo;//账号 
	private String  accountName;//账号 
	private String  midType;//商户类型
	
	private String  cycle;//结算周期
	private String  addr;//商户地址
	private String realName;//所属代理商中文
	private String alloatName; //分配姓名
	
	@Override
	protected String getOrderPartOfHQL() {
		
	return "ORDER BY TR.CREATEDATE ASC ";
		}

	@Override
	protected String getRowCountHQL() {
		StringBuffer  sb= new StringBuffer();		
//		if(!roleId.equals(Role.RISK_CONTROL_LEAD.getCode()) && merinfoFlag==4 ){//领件
			sb.append(" SELECT COUNT(1) ")
			.append(" FROM T_RECEIVE TR,TBL_EDIT_MCHT_INF A,(SELECT T1.INS_ID_CD, T1.INS_NAME FROM TBL_INS_INF T1) TI,TBL_EDIT_MCHT_BANKACCOUNT D,")
			.append("(SELECT T.ID,T.REAL_NAME,(SELECT TT.REAL_NAME FROM T_OPERATORS TT  WHERE TT.ID = TO_NUMBER(T.COMPANYID)) COMPANYNAME,")
			.append("(SELECT TT.REAL_NAME FROM T_OPERATORS TT WHERE TT.ID = TO_NUMBER(T.ONEAGENTID)) ONEAGENGNAME   FROM T_OPERATORS T) OP ")
			.append(" WHERE  A.MCHT_CD = D.OWNER_CD AND A.BANK_BELONG_CD = TI.INS_ID_CD")
			.append(" AND OP.ID = TO_NUMBER(A.EXT1)  AND TR.STATUS = '0' AND A.MCHT_CD = TR.MERNO ");
		
	/*	}*/
		return sb.toString();
	}

	 
	@Override
	protected String getSearchHQL() {
		StringBuffer  sb= new StringBuffer();
		    
		//	if(!roleId.equals(Role.RISK_CONTROL_LEAD.getCode()) && merinfoFlag==4){//领件（审核查询）
				sb.append("SELECT A.MCHT_CD,A.NAME_BUSI, A.NAME MERNAME,TI.INS_NAME,A.CONTACT_NAME,A.CONTACT_PHONENO,")
				.append(" A.CERTIF,A.CERTIF_NO,A.BUSI_LICE_NO,A.REG_ADDR,A.STATUS,OP.COMPANYNAME,OP.ONEAGENGNAME,")
				.append(" OP.REAL_NAME,D.NAME ACCOUNTNAME,D.ACCOUNT, D.BANK_NAME,D.BANK_CODE,TR.OP_ACCOUNTNAME")
				.append(" FROM TBL_EDIT_MCHT_INF A,(SELECT T1.INS_ID_CD, T1.INS_NAME FROM TBL_INS_INF T1) TI,TBL_EDIT_MCHT_BANKACCOUNT D, T_RECEIVE TR,")
				.append("(SELECT T.ID,T.REAL_NAME,(SELECT TT.REAL_NAME FROM T_OPERATORS TT  WHERE TT.ID = TO_NUMBER(T.COMPANYID)) COMPANYNAME,")
				.append("(SELECT TT.REAL_NAME FROM T_OPERATORS TT WHERE TT.ID = TO_NUMBER(T.ONEAGENTID)) ONEAGENGNAME   FROM T_OPERATORS T) OP ")
				.append(" WHERE  A.MCHT_CD = D.OWNER_CD AND A.BANK_BELONG_CD = TI.INS_ID_CD")
				.append(" AND OP.ID = TO_NUMBER(A.EXT1)  AND TR.STATUS = '0' AND A.MCHT_CD = TR.MERNO ");
			/*}*/
			 
		
		return sb.toString();
	}

	 
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		//if(null!=status && status.equals(MerinfoStatus.S_5.getCode())){//审核查询
			
			if((roleId.equals(Role.RISK_CONTROL_LEAD.getCode()) || roleId.equals(Role.SYSTEM.getCode())) && merinfoFlag==4){
				filedBeanList.add(new WhereHQLFieldBean(" A.STATUS ='"+MerinfoStatus.S_5.getCode()+"'  AND EXISTS (SELECT TR.MERNO FROM T_RECEIVE TR WHERE TR.STATUS='0' AND  TR.MERNO = A.MCHT_CD)"));
			}else{
				filedBeanList.add(new WhereHQLFieldBean(" A.STATUS ='"+MerinfoStatus.S_5.getCode()+"' "));
			}
	/*	}*/
		
		/*********************/
			
		if(Constance.isNotEmpty(merchantNo)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("A.MCHT_CD", merchantNo.trim(), "=", false));
		}
		 
		if(Constance.isNotEmpty(merBrName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("A.NAME", merBrName.trim(), "like", false,"ALL"));
		}
		
		if(Constance.isNotEmpty(merchantName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("A.NAME_BUSI", merchantName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(minDate)&&Constance.isNotEmpty(maxDate)){ //入网时间
			filedBeanList.add(new WhereHQLFieldBean("A.APPL_DATE",minDate,">=", false));
       	    filedBeanList.add(new WhereHQLFieldBean("A.APPL_DATE",maxDate,"<=", false));
		}
	
		if(Constance.isNotEmpty(certifName)){ //法人
			filedBeanList.add(new WhereHQLFieldBean("A.CERTIF", certifName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(cardNo)){ //法人身份证号
			filedBeanList.add(new WhereHQLFieldBean("A.CERTIF_NO", cardNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(contactName)){ //业务联系人
			filedBeanList.add(new WhereHQLFieldBean("A.CONTACT_NAME", contactName.trim() ,"like", false,"ALL"));
		} 
		if(Constance.isNotEmpty(phone)){ //业务联系电话
			filedBeanList.add(new WhereHQLFieldBean("A.CONTACT_PHONENO", phone.trim(), "=", false));
		} 
		if(Constance.isNotEmpty(accountNo)){ //结算账号
			filedBeanList.add(new WhereHQLFieldBean("D.ACCOUNT", accountNo.trim(), "=", false));
		} 
		if(Constance.isNotEmpty(accountName)){ //结算账户名称
			filedBeanList.add(new WhereHQLFieldBean("D.NAME", accountName.trim() ,"like", false,"ALL"));
		}
		
		
		
		
		if(Constance.isNotEmpty(realName)){//代理商中文(模糊)
			filedBeanList.add(new WhereHQLFieldBean("op.REAL_NAME", realName.trim(), "like", false,"ALL"));
		}
		return filedBeanList;
	}


	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}



	public String getMerBrName() {
		return merBrName;
	}

	public void setMerBrName(String merBrName) {
		this.merBrName = merBrName;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	

	


	

	public String getMidType() {
		return midType;
	}

	public void setMidType(String midType) {
		this.midType = midType;
	}

	
	public String getCycle() {
		return cycle;
	}

	public void setCycle(String cycle) {
		this.cycle = cycle;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public long getAgentId() {
		return agentId;
	}

	public void setAgentId(long agentId) {
		this.agentId = agentId;
	}


	public void setMerinfoFlag(int merinfoFlag) {
		this.merinfoFlag = merinfoFlag;
	}

	public int getMerinfoFlag() {
		return merinfoFlag;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}


	public String getOpId() {
		return opId;
	}

	public void setOpId(String opId) {
		this.opId = opId;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}


	public String getContactName() {
		return contactName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	public String getCertifName() {
		return certifName;
	}

	public void setCertifName(String certifName) {
		this.certifName = certifName;
	}

	public String getAccountNo() {
		return accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	public String getAccountName() {
		return accountName;
	}

	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}

	public String getAlloatName() {
		return alloatName;
	}

	public void setAlloatName(String alloatName) {
		this.alloatName = alloatName;
	}


	

	
}
